//
//  UserViewController.m
//  ZhihunewPaper
//
//  Created by 梅杰 on 16/7/10.
//  Copyright © 2016年 梅杰. All rights reserved.
//

#import "UserViewController.h"
#import <objc/runtime.h>
@interface UserViewController ()
@property (nonatomic,weak) UIButton *headViewButton;
@property (nonatomic,weak) UITextField *messageField;
@property (nonatomic,weak) UIButton *lagoutButton;
@end

@implementation UserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"个人主页";
    [self initWeight];
//    [self tryMemberFunc];

    

}
- (void) initWeight{
    UIButton *headButton = [[UIButton alloc] init];
    self.headViewButton = headButton;
    __weak typeof(self) __wakeme = self;
    [self.view addSubview:headButton];
    [headButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(__wakeme.view).offset(40);
        make.centerX.equalTo(__wakeme.view);
        make.height.equalTo(headButton.mas_width);
        make.width.equalTo(__wakeme.view).dividedBy(4);
    }];
    [headButton layoutIfNeeded];
//    [headButton setBackgroundColor:[UIColor redColor]];
    headButton.layer.cornerRadius = headButton.frame.size.width/2;
    headButton.layer.masksToBounds = YES;
    [headButton setImage:[UIImage imageNamed:@"Dark_Menu_Avatar"] forState:UIControlStateNormal];
    
    
    UITextField *textField = [[UITextField alloc] init];
    self.messageField = textField;
    [self.view addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(headButton);
        make.width.equalTo(headButton).multipliedBy(2);
        make.top.equalTo(headButton.mas_bottom).offset(20);
        make.height.mas_equalTo(30);
    }];
    UIButton *editButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,20,20)];
    UIView *blockView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [editButton addTarget:self action:@selector(rightViewButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    textField.leftView = blockView;
    textField.leftViewMode = UITextFieldViewModeUnlessEditing;
    UIImage *image = [UIImage imageNamed:@"Profile_Editname_Button"];
    [editButton setImage:image forState:UIControlStateNormal];
//    CGRect d = editButton.frame;
    
//    editButton.backgroundColor = [UIColor redColor];
    textField.rightView = editButton;
    textField.textAlignment = NSTextAlignmentCenter;
    textField.rightViewMode = UITextFieldViewModeUnlessEditing;
//    textField.backgroundColor = [UIColor blueColor];
    textField.text = @"梅杰";
    
    UIButton *logoutButton = [[UIButton alloc] init];
    logoutButton.backgroundColor = [UIColor whiteColor];
    self.lagoutButton = logoutButton;
    [self.view addSubview:logoutButton];
    [logoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(__wakeme.view).offset(-60);
        make.centerX.equalTo(headButton);
        make.width.equalTo(__wakeme.view).dividedBy(1.5);
        make.height.mas_equalTo(40);
    }];
    [logoutButton layoutIfNeeded];
    [[logoutButton titleLabel] setFont:[UIFont systemFontOfSize:16]];
    [logoutButton setTitle:@"登出" forState:UIControlStateNormal];
    [logoutButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    logoutButton.layer.borderColor = [UIColor grayColor].CGColor;
    logoutButton.layer.borderWidth = 1;
    logoutButton.layer.cornerRadius = logoutButton.frame.size.height / 2;
    logoutButton.layer.masksToBounds = YES;
    
}
- (void) rightViewButtonClicked :(UIButton *) sender{
    if (!self.messageField.isEditing) {
        [self.messageField becomeFirstResponder];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void) test{
    NSLog(@"abcv");
}
/*
- (void)tryMemberFunc
{
    unsigned int count = 0;
    Method *memberFuncs = class_copyMethodList([UIBarButtonItem class], &count);//所有在.m文件显式实现的方法都会被找到
    for (int i = 0; i < count; i++) {
        SEL name = method_getName(memberFuncs[i]);
        NSString *methodName = [NSString stringWithCString:sel_getName(name) encoding:NSUTF8StringEncoding];
        NSLog(@"member method:%@", methodName);
    }
//    [[UIBarButtonItem alloc]init]  ;
}
 */

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
